﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;
using System.Configuration;
using COP.Plan;

namespace COP.Providers
{
    public class XMLConfigProvider : IConfigProvider
    {
        private static XmlDocument doc = new XmlDocument();

        public XMLConfigProvider() { }

        string source = null;
        public XMLConfigProvider(string source)
        { this.source = source; }

        public object LoadConfig()
        {
            if (!string.IsNullOrEmpty(this.source))
            {
                XmlDocument docu = new XmlDocument();
                docu.Load(this.source);
                return docu;
            }
            else if (string.IsNullOrEmpty(doc.InnerXml))
            {
                COPSettings section = (COPSettings)ConfigurationManager.GetSection("COPSettings");
                doc.Load(section.XMLSource.Path); // @"C:\Users\VGupta\Documents\Visual Studio 2010\Projects\ClientApp\COP\Plan\Config.xml");
                return doc;
            }
            else
                return doc;
        }
    }
}